//
//  SystemUtil.m
//  Yueshi
//
//  Created by yueshi_tech on 15/7/15.
//  Copyright (c) 2015年 悦食中国. All rights reserved.
//

#import "SystemUtil.h"
#import "Reachability.h"



@implementation SystemUtil

+(NSString *)getAppVersion{
    // 获得当前打开软件的版本号
    NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
    NSString* versionNum =[infoDict objectForKey:@"CFBundleShortVersionString"];
    return versionNum;
}

+(NSString *)getImei{
    NSString *imei = [DefaultsHelper stringForKey:kUUID];
    if(ISBLANK(imei)){
        //获取一个uuid，然后存入userdefault
        imei = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
        [DefaultsHelper setObject:imei forKey:kUUID];
    }
    return imei;
}

+(BOOL)isWifi{
    BOOL result = YES;
    Reachability *reach = [Reachability reachabilityWithHostName:@"www.apple.com"];
    switch ([reach currentReachabilityStatus]) {
        case NotReachable:
            result = NO;
            break;
        case ReachableViaWiFi:
            result = YES;
            break;
        case ReachableViaWWAN:
            result = NO;
            break;
    }
    return result;
}

+(NSString *)getNetType{
    Reachability *reachability = [Reachability reachabilityWithHostName:@"www.apple.com"];
    [reachability startNotifier];
    NetworkStatus netStatus = [reachability currentReachabilityStatus];
    NSString *status = @"unknow";
    if (netStatus == ReachableViaWiFi) {
        status = @"WIFI";
    }
    else if (netStatus == ReachableViaWWAN){
        status = @"3G";
    }
    return status;
}

+(BOOL)isHaveNetWorking{
    NetworkStatus status = [[Reachability reachabilityWithHostName:@"www.apple.com"] currentReachabilityStatus];
    if (status == NotReachable) {
        return NO;
    }else{
        return YES;
    }
}


@end
